import 'package:flutter/material.dart';
import '../../model/security_check.dart';
import '../../pages/security/the_checkbox.dart';
import '../../pages/station/station_helper.dart';
import '../../model/station.dart';

import '../../widgets/IconWidget.dart';
import '../../widgets/inputWidget.dart';
import '../../helper/Helper.dart';
import '../../helper/global_config.dart';
import '../../helper/uidata.dart';
import '../../model/report.dart';
import 'security_helper.dart';

class SecurityCheckEndPage extends StatefulWidget {
  @override
  SecurityCheckEndPage(this.stc1, this.added);
  final SecurityCheck stc1;
  final VoidCallback added;
  @override
  SecurityCheckEndPageState createState() => new SecurityCheckEndPageState();
}

class SecurityCheckEndPageState extends State<SecurityCheckEndPage> {
  late SecurityCheck X1;

  final TextEditingController c1 = new TextEditingController();
  final TextEditingController c2 = new TextEditingController();
  final TextEditingController c3 = new TextEditingController();
  final TextEditingController c4 = new TextEditingController();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    X1 = widget.stc1;
    c1.text = X1.Content;
    c2.text = X1.Problems;
    c3.text = X1.Works;
    c4.text = X1.Remark;
  }

  upload(BuildContext context) async {
    X1.Content = c1.text;
    X1.Problems = c2.text;
    X1.Works = c3.text;
    X1.Remark = c4.text;
    X1.State = 1;
    if (X1.ID == 0) {
      await SecurityCheck.Add(X1);
    } else {
      await SecurityCheck.Update(X1);
    }
    widget.added();
    Navigator.of(context).pop();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      //backgroundColor: Colors.white,
      appBar: AppBar(
        title: Text("检查结果填报"),
      ),
      body: SecurityCheckEndBody(context),
    );
  }

  void onEQMChange(String nn) {
    String yy = nn.toString();
    setState(() {
      X1.ExamQM = yy;
    });
  }

  SecurityCheckEndBody(BuildContext context) => SingleChildScrollView(
        child: SecurityCheckEndFields(context),
      );

  List<Widget> getWidgetList(BuildContext context) {
    List<Widget> list1 = <Widget>[];
    List<Widget> list2 = <Widget>[];
    List<Widget> list3 = <Widget>[];
    List<Widget> list4 = <Widget>[];

    list1.add(InputWidget.inCard(
      ListTile(
        leading: IconWidget.CheckImage(),
        title: Text(X1.Title),
      ),
    ));

    list2.add(InputWidget.getInput2("检查内容", c1));
    list2.add(Divider(
      height: 0.0,
    ));
    list2.add(InputWidget.getInput2("发现问题", c2));
    list2.add(Divider(
      height: 0.0,
    ));
    list2.add(InputWidget.getInput2("处置措施", c3));
    list2.add(Divider(
      height: 0.0,
    ));
    list2.add(InputWidget.getInput2("备注", c4));
    list2.add(Divider(
      height: 0.0,
    ));

    list1.add(InputWidget.inCard2(list2));

    list1.add(
        InputWidget.inCard(InputWidget.getButton("保存", () => upload(context))));

    //list1.add(getCLWidget(s1.State==6, Helper.DateTimeFormat(s1.HZQMTM), s1.HZQM));
    return list1;
  }

  SecurityCheckEndFields(BuildContext context) {
    return Container(child: Column(children: getWidgetList(context)));
  }
}
